package day13.part2.demos;

/**
 * @Author juzipi
 * @Date 2021/6/29 15:53
 * @Info
 */
public class Order {

    private String name;

    private String age;

    public Order(String name, String age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (age != null ? age.hashCode() : 0);
        return result;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o){
            return true;
        }
        if (o instanceof Order){
            Order order = (Order) o;
            //不为空就是 true，再通过equals判断，不为false就跳过
            if (this.age != null ? !this.age.equals(order.age) : order.age != null){
                return false;
            }
            //基本数据类型就用 == ，引用数据类型还是要用equals比较
            return this.name != null ? this.name.equals(order.name) : order.name == null;
        }
        return false;

    }


//    @Override
//    public boolean equals(Object o) {
//        if (this == o) return true;
//        if (o == null || getClass() != o.getClass()) return false;
//
//        Order order = (Order) o;
//
//        if (name != null ? !name.equals(order.name) : order.name != null){
//            return false;
//        }
//        return age != null ? age.equals(order.age) : order.age == null;
//    }
}

class OrderTest{

    public static void main(String[] args) {
        Order order = new Order("张三","20");
        Order order1 = new Order("张三","20");
        System.out.println(order.equals(order1));

    }

}
